﻿using Sodu.Entity;
using Sodu.Util;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// “用户控件”项模板在 http://go.microsoft.com/fwlink/?LinkId=234236 上提供

namespace Sodu.UC
{
    public sealed partial class UC_BookListItem : UserControl
    {

        /// <summary>
        /// 是否被选中
        /// </summary>
        public bool Checked
        {
            get
            {
                return this.checkbox.IsChecked == true ? true : false;
            }
            set
            {
                this.checkbox.IsChecked = value;
            }
        }


        /// <summary>
        /// 传递的实体
        /// </summary>
        public BookEntity Entity = new BookEntity();

        public string ContentsUrl = string.Empty;

        public bool HadClick = false;
        public UC_BookListItem(BookEntity t_entity)
        {
            this.InitializeComponent();
            this.Entity = t_entity;

            if (Entity.Bookshelf == false)
            {
                this.gridOfCheckBox.Width = new GridLength(0);
                this.checkbox.Visibility = Visibility.Collapsed;
            }

            this.txtBookName.Text = Entity.BookName;
            this.txtChapterName.Text = Entity.ChapterName;
            this.txtUnreadData.Text = Entity.UnReadCountData;
            this.txtUpdateTime.Text = Entity.UpdateTime;
            this.ContentsUrl = Entity.ContentsUrl;
        }


        async private void Uc_BookItem_PointerReleased(object sender, PointerRoutedEventArgs e)
        {
            HadClick = true;
            await MessageBox.Show(this.ContentsUrl);
        }

        private void grid_PointerEntered(object sender, PointerRoutedEventArgs e)
        {
            this.grid.Background = new SolidColorBrush(Color.FromArgb(255, 192, 232, 112));
        }

        private void grid_PointerExited(object sender, PointerRoutedEventArgs e)
        {
            if (!HadClick)
            {
                this.grid.Background = new SolidColorBrush(Colors.Transparent);
            }
        }

        private void grid_PointerCaptureLost(object sender, PointerRoutedEventArgs e)
        {
            if (!HadClick)
            {
                this.grid.Background = new SolidColorBrush(Colors.Transparent);
            }
        }


    }
}
